using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEditor.Progress;

public class ItemManager : PersistentSingleton<ItemManager>
{
    private FactoryManger<Item, ItemData> itemFactory;
    public FactoryManger<Item, ItemData> ItemFactory
    {
        get => itemFactory; 
    }
    protected override void Awake()
    {
        base.Awake();
        itemFactory=new FactoryManger<Item, ItemData>();
        itemFactory.LoadJson("Data/itemData.json");
    }
    public List<Item> GetAllItems() => itemFactory.instanceList;

    public List<Item> GetItemKinds(string kind)
    {
        return ItemFactory.instanceList.FindAll(item => item.Data.Kinds==kind);
    }
    public Item GetItem(int id)
    {
        Item item = itemFactory.GetInstance(id);
        if (item != null)
        {
            return item;
        }
        return null;
    }
    public Item GetItem(string name)
    {
        Item item = itemFactory.GetInstance(name);
        if (item != null)
        {
            return item;
        }
        return null;
    }
}
